<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="创建时间" prop="gmtCreate">
      <el-input v-model="dataForm.gmtCreate" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="gmtModified">
      <el-input v-model="dataForm.gmtModified" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="code" prop="orderCode">
      <el-input v-model="dataForm.orderCode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="用户名" prop="orderUserName">
      <el-input v-model="dataForm.orderUserName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="渠道" prop="orderChannel">
      <el-input v-model="dataForm.orderChannel" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="尺寸（宽）" prop="orderImageWidth">
      <el-input v-model="dataForm.orderImageWidth" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="尺寸（高）" prop="orderImageHeight">
      <el-input v-model="dataForm.orderImageHeight" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="客单价" prop="orderUnitPrice">
      <el-input v-model="dataForm.orderUnitPrice" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="orderRemark">
      <el-input v-model="dataForm.orderRemark" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="orderStatus">
      <el-input v-model="dataForm.orderStatus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="订单图" prop="orderImageUrl">
      <el-input v-model="dataForm.orderImageUrl" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="商品code" prop="orderItemCode">
      <el-input v-model="dataForm.orderItemCode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="扩展" prop="extInfo">
      <el-input v-model="dataForm.extInfo" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="环境" prop="env">
      <el-input v-model="dataForm.env" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          gmtCreate: '',
          gmtModified: '',
          orderCode: '',
          orderUserName: '',
          orderChannel: '',
          orderImageWidth: '',
          orderImageHeight: '',
          orderUnitPrice: '',
          orderRemark: '',
          orderStatus: '',
          orderImageUrl: '',
          orderItemCode: '',
          extInfo: '',
          env: ''
        },
        dataRule: {
          gmtCreate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderUserName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderChannel: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderImageWidth: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderImageHeight: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderUnitPrice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderRemark: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderStatus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderImageUrl: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderItemCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          extInfo: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          env: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/order/order/queryWormholeGalaxyOrder`),
              method: 'get',
              data: this.$http.adornData({
                "id":id
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.gmtCreate = data.wmhGalaxyOrder.gmtCreate
                this.dataForm.gmtModified = data.wmhGalaxyOrder.gmtModified
                this.dataForm.orderCode = data.wmhGalaxyOrder.orderCode
                this.dataForm.orderUserName = data.wmhGalaxyOrder.orderUserName
                this.dataForm.orderChannel = data.wmhGalaxyOrder.orderChannel
                this.dataForm.orderImageWidth = data.wmhGalaxyOrder.orderImageWidth
                this.dataForm.orderImageHeight = data.wmhGalaxyOrder.orderImageHeight
                this.dataForm.orderUnitPrice = data.wmhGalaxyOrder.orderUnitPrice
                this.dataForm.orderRemark = data.wmhGalaxyOrder.orderRemark
                this.dataForm.orderStatus = data.wmhGalaxyOrder.orderStatus
                this.dataForm.orderImageUrl = data.wmhGalaxyOrder.orderImageUrl
                this.dataForm.orderItemCode = data.wmhGalaxyOrder.orderItemCode
                this.dataForm.extInfo = data.wmhGalaxyOrder.extInfo
                this.dataForm.env = data.wmhGalaxyOrder.env
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/order/${!this.dataForm.id ? 'createWormholeGalaxyOrder' : 'createWormholeGalaxyOrder'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'gmtModified': this.dataForm.gmtModified,
                'orderCode': this.dataForm.orderCode,
                'orderUserName': this.dataForm.orderUserName,
                'orderChannel': this.dataForm.orderChannel,
                'orderImageWidth': this.dataForm.orderImageWidth,
                'orderImageHeight': this.dataForm.orderImageHeight,
                'orderUnitPrice': this.dataForm.orderUnitPrice,
                'orderRemark': this.dataForm.orderRemark,
                'orderStatus': this.dataForm.orderStatus,
                'orderImageUrl': this.dataForm.orderImageUrl,
                'orderItemCode': this.dataForm.orderItemCode,
                'extInfo': this.dataForm.extInfo,
                'env': this.dataForm.env
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
